package com.asm.DBloader;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class ASM_FCompanyBranchDS {
	private SQLiteDatabase dB;
	private ASM_DB dbHelper;
	Context context;

	
	public ASM_FCompanyBranchDS (Context context)
	{
		this.context = context;
		dbHelper = new ASM_DB(context);
	}
	
	public void open() throws SQLException
	{
		dB = dbHelper.getWritableDatabase();
	}
	
	public int Create(ASM_FCompanyBranch det) {
		
		int count =0;
		
		if(dB == null){
			open();
		}else if(!dB.isOpen()){
			open();
		}
		
		 
	
		ContentValues values = new ContentValues();
		values.put(ASM_DB.asmFCompanyBranch_cSettingsCode, det.getAsmFCompanyBranch_cSettingsCode());
		values.put(ASM_DB.asmFCompanyBranch_BranchCode, det.getAsmFCompanyBranch_BranchCode());
		values.put(ASM_DB.asmFCompanyBranch_nNumVal,det.getAsmFCompanyBranch_nNumVal());
		values.put(ASM_DB.asmFCompanyBranch_RecordId, det.getAsmFCompanyBranch_RecordId());
		

		
		count = (int) dB.insert(ASM_DB.ASM_FCOMPANYBRANCH, null, values);

		dB.close();
		return count;
		
	}
	
	public String getFcompanybranch(String cSettingsCode) 
	{
		if (dB == null) {
			open();
		} else if (!dB.isOpen()) {
			open();
		}
		
		
		String NewRefno = null;
		String selectQuery = "select nNumVal from fCompanyBranch where cSettingsCode = '"+cSettingsCode+"'";
		
		Cursor cursor = null;
		cursor = dB.rawQuery(selectQuery, null);
		if(cursor!=null)
		{
			while(cursor.moveToNext())
				{
			
//			Details.add(cursor.getString(0));
//			Details.add(cursor.getString(1));
//			Details.add(cursor.getString(2));
			NewRefno = cursor.getString(0);
//			Details.add(cursor.getString(3));
						
				}
			
		}
		else
		{
			NewRefno = "1";
		}
		
		return NewRefno;
	}
}
